/*
 * @Descripttion: 
 * @Author: zhangchong zc16607@gmail.com
 * @Date: 2023-02-27 16:08:44
 * @LastEditors: zhangchong zc16607@gmail.com
 * @LastEditTime: 2023-03-03 09:35:48
 */
const express = require('express')
const cors = require('cors')
const compression = require('compression')
const { expressjwt } = require('express-jwt')
const { Cache } = require('./cache/index')


function initMiddleware(app) {
  app.use(express.json())
  // for parsing application/x-www-form-urlencoded
  app.use(express.urlencoded({ extended: true }))
  // 跨域
  app.use(cors())
  // 压缩，js、css文件
  app.use(compression())
  // app.use(express.static(path.join(__dirname, 'public')))
  // 接口鉴权
  app.use(expressjwt({ secret: 'express-auth', algorithms: ['HS256'] }).unless({ path: ["/api/login"] }))

  // 接口缓存
  app.use(Cache(app))
}

module.exports = initMiddleware